home *** CD-ROM | disk | FTP | other *** search
- {
- ***
-
- HEXFUNCS.PAS
- Unit Implementing Decimal-Hexadecimal and Hexadecimal-Decimal Conversions
- (C)Copyright Gerard Paul Java 1996
-
- ***
- }
-
- unit HexFuncs;
-
- interface
-
- type
- HexByte = string[2];
-
- function ToHex(X: byte): HexByte;
- function FromHex(Digit: char): byte;
-
- implementation
-
- function ToHex(X: byte): HexByte;
- var
- Digit1,
- Digit2: byte;
-
- function HexOneDigit(Y: byte): char;
- var
- Result: byte;
-
- begin
- if Y < $A then
- Result := Y
- else
- Result := Y+7;
-
- Inc(Result,48);
-
- HexOneDigit := Chr(Result);
- end;
-
- begin
- Digit1 := X mod 16;
- Digit2 := X div 16;
-
- ToHex := HexOneDigit(Digit2)+HexOneDigit(Digit1);
- end;
-
- function FromHex(Digit: char): byte;
- begin
- case Digit of
- '0'..'9': FromHex := Ord(Digit)-48;
- 'A'..'F': FromHex := Ord(Digit)-55;
- end;
- end;
-
- end.
-